package com.hetwen.remoteboot.packet;

import com.hetwen.remoteboot.utils.ConvertUtils;

public class MagicPacket {

	/**
	 * Magic Packet
	 */
	public static final int MAGIC_PACKET_LENGTH = 102;
	
	private String mac;
	
	public MagicPacket() {
	}

	/**
	 * @param mac
	 */
	public MagicPacket(String mac) {
		this.mac = mac;
	}
	
	/**
	 * 
	 * @return Magic Packet��ݰ��ֽ�����
	 */
	public byte[] getMagicPacketBytes(){
		
		byte[] mac_bytes = ConvertUtils.getBytesFromHexString(this.mac);
		
		if(mac_bytes.length != 6)
		{
			return null;
		}
		
		byte[] packet = new byte[MAGIC_PACKET_LENGTH];
		
		for(int i = 0;i<6;i++)
		{
			packet[i] = (byte) 0xFF;
		}
		
		
		for(int i = 6,j = 0;i < MAGIC_PACKET_LENGTH; i++,j++)
		{
			if(i % 6 == 0)
			{
				j = 0;
			}
			packet[i] = mac_bytes[j];
		}
		
		return packet;
	}
}
